package Test;

import java.util.Scanner;

public class Test04 {



    //装箱问题
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] v = new int[m+1];
        int[] f = new int[20010];
        for(int i = 1;i<=m;i++){
            v[i] = sc.nextInt();
        }
        for(int i = 1;i<=m;i++){
            for(int j = n;j>=0;j--){
                if(j < v[i]) f[j] = f[j];
                else f[j] = Math.max(f[j],f[j-v[i]]+v[i]);
            }
        }
        //     for(int i = 1 ; i <= m ; i ++ ){
        //       for(int j = n ; j >= 0 ; j -- ){
        //           if(j >= v[i])f[j] = Math.max(f[j],f[j - v[i]] + v[i]);
        //       }
        //   }
        int ret = n - f[n];
        System.out.println(ret);
    }

}
